# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>

pkgbase=sord
pkgname=(sord sord-docs)
pkgver=0.16.14
pkgrel=1
pkgdesc="A lightweight C library for storing RDF data in memory"
arch=(loong64 x86_64)
url="https://drobilla.net/software/sord.html"
license=(custom:ISC)
makedepends=(doxygen glibc meson pcre python-sphinx serd)
options=(debug)
source=(https://download.drobilla.net/$pkgname-$pkgver.tar.xz{,.sig})
sha512sums=('f6f254518d5dccece7975529b1fcfd552fd9c37e49dc7e9f8a46756b85e476dac064a39af42bfb3078e999e75d1aa75dcc30ec91e08753defa9363adafdfd3bd'
            'SKIP')
b2sums=('399f4bf5d1b8ae557fa7e2d2e92e74ed646d0554235f4527a4b9ad53aa6beb0e90e2d80c9e65ab3c872b5c8d45a7948b7746284bb1fd2352320a0aa33e97e305'
        'SKIP')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package_sord() {
  depends=(glibc libserd-0.so pcre)
  provides=(libsord-0.so)
  optdepends=('sord-docs: for developer documentation')

  meson install -C build --destdir "$pkgdir"
  (
    cd "$pkgdir"
    _pick $pkgname-docs usr/share/doc
  )
  install -vDm 644 $pkgname-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_sord-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
  mv -v "$pkgdir/usr/share/doc/"sord{-0,}
}
